#ifndef CJDEVICE_H
#define CJDEVICE_H
#include <QThread>
#include <QObject>
#include "modbus.h"
#include <QTimer>
typedef  struct OneBattery
{
    float voltage;
    float temperature;
    float NeiZhu;

}OneBattery;

typedef struct AGroupBattery
{
    OneBattery battery[255];//预设最大电池节数255

} AGroupBattery;
class CJDevice:public QObject
{
    Q_OBJECT
public:
    CJDevice();
    ~CJDevice();
    QThread thread;
    AGroupBattery gropBattery;
    Modbus *modbus;
    QTimer *timer;
    int batteryNumber=0;
    int batteryNumberOld=0;
    void OpenPort(QString portName,int baudRate);   //供外部调用，在线程内打开端口
    void ClosePort();
    void SignalSlotsInit();
    void StartTimer();                              //外部调用启动内部定时器
    void StopTimer();                               //外部调用停止内部定时器
    void SlotsInit();                               //对象创建后调用槽函数初始化
    void SendFc3(unsigned char, ushort, ushort, ushort*,bool*);                  //供外部调用
    void SendFc16(unsigned char, ushort, ushort,ushort *,bool *);
    void SendFc6(unsigned char address, ushort start, ushort registers, ushort*values);
signals:
    void Signal_ToCreateMembers();
    void Signal_ToOpenPort(QString);
    void Signal_ToClosePort();
    void Siganl_ToShowValueData(AGroupBattery);
    void Signal_ToStartTimer();
    void Signal_ToStopTimer();
    void Signal_SendFc16(unsigned char, ushort, ushort, ushort*,bool *);
    void Siganl_SendFc3(unsigned char, ushort, ushort,ushort *,bool *);
    void Signal_SendFc6(unsigned char, ushort, ushort, ushort*);
public slots:
    void CreateMembers();
    void Slots_OpenPort(QString);
    void Slots_ClosePort();
    void Slots_TimerTimeOut();
    void Slots_ToStartTimer();
    void Slots_ToStopTimer();
    void Slot_SendFc16(unsigned char, ushort, ushort, ushort*,bool*);
    void Slot_SendFc3(unsigned char, ushort, ushort,ushort *,bool *);
    void Slots_sendFc6(unsigned char address, ushort start, ushort registers, ushort*values);

};

#endif // CJDEVICE_H
